<?php

/*
	Xiuno BBS 4.0 消息
*/

!defined('DEBUG') AND exit('Forbidden');
$msg = [];
// 获取数据库前缀
$tablepre = $db->tablepre;
// 需要删除的列
$columns_to_drop = ['post'=>'OK','thread'=>'OK','user'=>'OK','group'=>['see_check','post_check','thread_check','edit_check'],'forum'=>['post_check','thread_check','edit_check']];
$sqls = [];
foreach ($columns_to_drop as $tb => $field){
    $columns_sql = "SHOW COLUMNS FROM `{$tablepre}{$tb}`;";// 列出目标表的字段
    $cur_columns = db_sql_find($columns_sql, 'Field');
    if (!empty($cur_columns)) {
        if(!is_array($field)){
            $field = [$field];
        }
        foreach ($field as $column) {
            if(isset($cur_columns[$column])){// 如果列存在，则添加到ALTER TABLE语句中
                $sqls[$tb.'.'.$column] = "ALTER TABLE `{$tablepre}{$tb}` DROP `{$column}`;";
            }
        }
    }
}
foreach ($sqls as $column_exp => $sql){
    $r2 = db_exec($sql);
    $r2 === FALSE AND $msg[] = "Failed to delete {$tablepre}{$column_exp} field.";
}
// 清除插件设置
setting_delete('tt_check');

// 更新缓存，确保论坛信息的一致性
group_list_cache_delete();
forum_list_cache_delete();
if(!empty($msg)) message(-1,$msg);//显示错误信息
?>
